<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- <div ></div> -->
    <table id="app" border="1" cellspacing="0">
        <thead>
            <tr>
                <th>名称</th>
                <th>单价</th>
                <th>数量</th>
                <th>小计</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>{{list[0].name}}</td>
                <td>{{list[0].price}}</td>
                <td><input type="number" v-model="list[0].num"></td>
                <td>{{list[0].num * list[0].price}}</td>
            </tr>
            <tr>
                <td>{{list[1].name}}</td>
                <td>{{list[1].price}}</td>
                <td><input type="number" v-model="list[1].num"></td>
                <td>{{list[1].num * list[1].price}}</td>
            </tr>
            <tr>
                <td>{{list[2].name}}</td>
                <td>{{list[2].price}}</td>
                <td><input type="number" v-model="list[2].num"></td>
                <td>{{list[2].num * list[2].price}}</td>
            </tr>
            <tr>
                <td>{{list[3].name}}</td>
                <td>{{list[3].price}}</td>
                <td><input type="number" v-model="list[3].num"></td>
                <td>{{list[3].num * list[3].price}}</td>
            </tr>
            <tr>
                <td colspan="2">总计</td>
                <td>{{totalNum}}</td>
                <td>{{totalPrice}}</td>
            </tr>
        </tbody>
    </table>
    <script src="../vue.js"></script>
    <script>
        let vm = new Vue({
            el: '#app',
            data: {
                list: [
                    {
                        "name": "【DCH-30170200058】东成_合金钻头6*160圆柄(60202024)/[1支]",
                        "price": 3,
                        num: 5
                    },
                    {
                        "name": "博世（BOSCH）S3 四坑两刃钻头 12*400*460mm-(2608680280)/支",
                        "price": 26,
                        num: 4
                    },
                    {
                        "name": "【DCH-30170200038】东成_合金钻头12*150圆柄(60202004)/[1支]",
                        "price": 4,
                        num: 7
                    },
                    {
                        "name": "【DCH-30170200037】东成_合金钻头10*150圆柄(60202003)/[1支]",
                        "price": 4,
                        num: 5
                    },
                ]
            },
            computed: {
                totalNum() {
                    let num = 0;
                    for(let i = 0; i<this.list.length; i ++) {
                        num += this.list[i].num * 1 // 转为数字
                    }
                    return num+'件'
                },
                totalPrice() {
                    let num = 0;
                    for(let i = 0; i<this.list.length; i ++) {
                        num += this.list[i].num * this.list[i].price
                    }
                    return '¥'+num+'元'
                }
            }
        })
    </script>
</body>

</html>